<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首页</title>
    <link rel="shortcut icon" href="../imgs/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="../css/index.css">
    <script src="../js/ajax.js"></script>
</head>

<body>
    <div class="header">
        <div class="top">
            <a href="http://127.0.0.1:8000/html/shopCart.html" id="shop" target="_blank"><span>购物车</span></a>
            <a href="http://127.0.0.1:8000/html/login.html"><span>请登录</span></a>
            <a href="http://127.0.0.1:8000/html/register.html"><span>免费注册</span></a>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <span id="span" style="color: #333;"></span>
            <a href="http://127.0.0.1:8000/html/login.html" id="logout"><span id="span1">登出</span></a>
        </div>
    </div>
    <div id="box">
        <a href="http://127.0.0.1:8000/html/product_details.html?id=1" target="_blank" class="list">
            <div class="item1">
                <img src="../imgs/sp1.jpg" alt="">
                <div class="footer-item-title">统一来一桶老坛酸菜牛肉面 120g*3+红烧牛肉面 105g*3泡面组合</div>
                <div class="footer-price">￥23.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=2" target="_blank" class="list">
            <div class="item2">
                <img src="../imgs/sp2.jpg" alt="">
                <div class="footer-item-title">SELECTMOCA日本直邮2020年新品翻领机车夹克羊羔绒厚外套女</div>
                <div class="footer-price">￥58.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=3" target="_blank" class="list">
            <div class="item3">
                <img src="../imgs/sp3.jpg" alt="">
                <div class="footer-item-title">康夫电吹风机大功率发型师理发店专用电风吹负离子护发家用风筒</div>
                <div class="footer-price">￥118.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=4" target="_blank" class="list">
            <div class="item4">
                <img src="../imgs/sp4.jpg" alt="">
                <div class="footer-item-title">权志龙YGESHOP BIGBANG 棒球夹克 - Heidenei</div>
                <div class="footer-price">￥1111.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=5" target="_blank" class="list">
            <div class="item5">
                <img src="../imgs/sp5.jpg" alt="">
                <div class="footer-item-title">Huawei/华为 Mate 40 pro 5G手机官方旗舰店正品mate40pro+新p40直降mate50保时捷M40</div>
                <div class="footer-price">￥7999.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=6" target="_blank" class="list">
            <div class="item6">
                <img src="../imgs/sp6.jpg" alt="">
                <div class="footer-item-title">百草味 手撕面包1kg全麦整箱早餐饼干网红蛋糕点心礼盒装零食小吃</div>
                <div class="footer-price">￥59.9</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=7" target="_blank" class="list">
            <div class="item7">
                <img src="../imgs/sp7.jpg" alt="">
                <div class="footer-item-title">CANADA GOOSE / 加拿大鹅 Garson 马甲 4151M</div>
                <div class="footer-price">￥3099.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=8" target="_blank" class="list">
            <div class="item8">
                <img src="../imgs/sp8.jpg" alt="">
                <div class="footer-item-title">韩宇同款【经典款】Timberland添柏岚踢不烂男防水黄靴</div>
                <div class="footer-price">￥1490.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=9" target="_blank" class="list">
            <div class="item9">
                <img src="../imgs/sp9.jpg" alt="">
                <div class="footer-item-title">Apple/苹果 iPhone 12</div>
                <div class="footer-price">￥6299.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=10" target="_blank" class="list">
            <div class="item10">
                <img src="../imgs/sp10.jpg" alt="">
                <div class="footer-item-title">四川爱媛38号果冻橙10斤装橙子新鲜当季水果整箱柑橘蜜桔子包邮甜</div>
                <div class="footer-price">￥22.9</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=11" target="_blank" class="list">
            <div class="item11">
                <img src="../imgs/sp11.jpg" alt="">
                <div class="footer-item-title">联想无线运动型跑步蓝牙耳机双耳颈挂脖入耳挂耳头戴式单超长待机续航适用苹果x安卓8小米vivo华为oppo通用11</div>
                <div class="footer-price">￥169.0</div>
            </div>
        </a>
        <a href="http://127.0.0.1:8000/html/product_details.html?id=12" target="_blank" class="list">
            <div class="item12">
                <img src="../imgs/sp12.jpg" alt="">
                <div class="footer-item-title">小米充电宝移动电源10000毫安快充超薄小巧便携大容量迷你18w高速 </div>
                <div class="footer-price">￥79.0</div>
            </div>
        </a>
    </div>
    <script>
        window.onload = function () {
            let span = document.getElementById("span")
            let shop = document.getElementById('shop')
            let span1 = document.getElementById('span1')
            let dataMsg = JSON.parse(localStorage.getItem("dataMsg"))
            let sessionid = getCookie("sessionid")
            if (sessionid != null) {
                span.innerHTML = "你好，" + dataMsg.msg.userInfo.name
                span1.innerHTML = "登出"
            } else {
                span1.innerHTML = ""
            }

            shop.onclick = function () {
                if (sessionid == null) {
                    window.location.href = "http://127.0.0.1:8000/html/login.html"
                }
            }
            let logout = document.getElementById('logout')
            let username = getCookie("username")

            logout.onclick = function () {
                if (username != null) {
                    Ajax.post('http://127.0.0.1:8000/logout', JSON.stringify(username), (data) => {
                        console.log(data)

                    })
                }
            }

            function getCookie(name) {
                var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
                if (arr = document.cookie.match(reg))
                    return unescape(arr[2]);
                else
                    return null;
            }
        }
    </script>
</body>

</html>